#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File   : tsTcpClnt.py
# @Email  : xuexia_xu@feidee.com
# @Time   : 2024/4/3 17:39
# @Desc   : 《Python核心编程第3版》示例 2-1 TCP 时间戳客户端

from socket import *

HOST = '127.0.0.1'
PORT = 21567
BUFSIZ = 1024
ADDR = (HOST, PORT)
# 创建客户端套接字
tcpCliSock = socket(AF_INET, SOCK_STREAM)
# 尝试连接服务器
tcpCliSock.connect(ADDR)

while True:
    data = input('>')
    if not data:
        break
    tcpCliSock.send(data.encode())
    data = tcpCliSock.recv(BUFSIZ)
    if not data:
        break
    print(data.decode('utf-8'))
tcpCliSock.close()
